﻿namespace MicroCloud.Authorization.Database
{
    #region "模块功能信息数据实体映射配置"
    /// <summary>
    /// 模块功能信息数据实体映射配置
    /// </summary>
    public class ModuleFunctionConfiguration : EntityTypeConfigurationBase<ModuleFunction, long>
    {
        #region "方法"
        #region "重写以实现实体类型各个属性的数据库配置"
        /// <summary>
        /// 重写以实现实体类型各个属性的数据库配置
        /// </summary>
        /// <param name="builder">实体类型创建器</param>
        public override void Configuration(EntityTypeBuilder<ModuleFunction> builder)
        {
            //builder.HasIndex(m => new { m.ModuleId, m.FunctionId }).HasDatabaseName($"IDX_{EntityName}_ModuleFunctionId").IsUnique();
            builder.HasIndex(m => new { m.ModuleId, m.FunctionId }).SetIndex("ModuleFunctionId", true);

            //builder.HasOne(mf => mf.Module).WithMany().HasForeignKey(m => m.ModuleId).HasConstraintName($"FK_{EntityName}_ModuleId").IsRequired();
            //builder.HasOne(mf => mf.Function).WithMany().HasForeignKey(m => m.FunctionId).HasConstraintName($"FK_{EntityName}_FunctionId").IsRequired();
            builder.HasOne(mf => mf.Module).WithMany().HasForeignKey(m => m.ModuleId).SetForeignKey("ModuleId");

            ConfigurationAppend(builder);
        }
        #endregion

        #endregion

    }
    #endregion

}
